package leetcode.code1043;

import leetcode.IDebug;

public class Solution implements IDebug {
	public int maxSumAfterPartitioning(int[] arr, int k) {
		int n = arr.length;
		int[] dp = new int[n + 1];
		for (int i = 1; i <= n; i++) {
			int max = 0;
			for (int j = 0; j < Math.min(k, i); j++) {
				max = Math.max(max, arr[i - 1 - j]);
				dp[i] = Math.max(dp[i], dp[i - 1 - j] + max * (j + 1));
			}
		}
		return dp[n];
	}

	public int maxSumAfterPartitioning1(int[] arr, int k) {
		int n = arr.length;
		int[] dp = new int[n + 1];
		for (int i = 1; i <= n; i++) {
			int max = 0;
			for (int j = 0; j < k && i - 1 - j >= 0; j++) {
				max = Math.max(max, arr[i - 1 - j]);
				dp[i] = Math.max(dp[i], dp[i - 1 - j] + max * (j + 1));
			}
		}
		return dp[n];
	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
